package com.ftf.tp.user.infrastructure.adapter.producer;

import com.ftf.tp.common.core.utils.SpringEventPublisher;
import com.ftf.tp.user.application.adapter.producer.DomainEventPublisher;
import com.ftf.tp.common.domain.BaseDomainEvent;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * @author tanghao
 * @date 2022/8/5
 */
@Component
public class DomainEventPublisherImpl implements DomainEventPublisher {

    @Resource
    private RocketMQTemplate rocketMqTemplate;

    /**
     * 发布事件 到微服务内部
     *
     * @param event event
     */
    @Override
    public <EVENT extends BaseDomainEvent<?>> void publishInternal(EVENT event) {
        SpringEventPublisher.publishEvent(event);
    }

    /**
     * 发布事件 到微服务外部 同步
     *
     * @param event event
     */
    @Override
    public <EVENT extends BaseDomainEvent<?>> void publishExternalSync(EVENT event, String topic) {
        rocketMqTemplate.syncSend(topic, event);
    }

    /**
     * 发布事件并保存
     *
     * @param event event
     */
    @Override
    public <EVENT extends BaseDomainEvent<?>> void publishAndSave(EVENT event) {

    }
}
